|
|
|
|
|
|
|
Modifying Random Access Files |
|
|
|
|
|
|
|
|
The process for modifying a random access file is as follows: |
|
|
|
|
|
|
|
|
1. Assign rows from the file into variables. |
|
|
|
|
|
|
|
|
2. Modify the values in the variables. |
|
|
|
|
|
|
|
|
3. Persist the values in the variables back to the file. |
|
|
|
|
|
|
|
|
You read about the Open part of step 1 in Listing 17.1. The assignment of rows to variables requires the use of the Get statement as follows: |
|
|
|
|
|
|
|
|
Dim lPosition As Long
. . .
Get #iFileNumber, lPosition, Teller1Trans |
|
|
|
|
|
|
|
|
The Get statement uses iFileNumber to open a file and to assign it the number contained in the variable. You can view iFileNumber as similar to an index that differentiates one open file from another (in those cases where you might have more than one file open simultaneously). lPosition contains the row number of the row to copy. It is like a primary index or row identifier. The Teller1Trans user-defined type receives the contents of the row in columnar fashion. That is, each column is assigned to each member variable of the UDT. |
|
|
|
|
|
|
|
|
Step 2 represents whatever you want to do to the values in code. In the case of the Teller1Trans UDT, you probably wouldn't want someone to modify it because a transaction is really a historical archive used for auditing (read-only) purposes anyway. However, if you have a UDT that has, say, a LastName variable, and a person got married or simply changed his or her name for whatever reason, or a data entry person made a mistake in typing, you'd definitely want the ability to modify information. |
|
|
|
|
|
|
|
|
Step 3 involves persisting (or storing) the information modified back to the file. Use the Put statement for this operation. The Put statement is generally coupled with the Get statement in managing random access files. It has a very similar syntax as the Get statement. |
|
|
|
|
|
|
|
|
To replace records, use a Put statement, specifying the position of the record you want to replacefor example, |
|
|
|
|
|
|
|
|
Put #iFileNumber, lPosition, Teller1Trans |
|
|
|
|
|
|
|
|
The row identified with lPosition will be modified accordingly. |
|
|
|
|
|